/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package myftp.app.action;

import java.io.IOException;
import myftp.app.model.ServerModel;
import myftp.app.view.PromptPartView;
import myftp.app.view.dialog.TemplateDialog;
import myftp.core.Template;
import myftp.core.action.AbstractAction;

/**
 *
 * @author CAVARLE Glenn, LUCAS Stéphane
 * Affiche les messages reçu du serveur dans le prompt
 */
public class PromptAction extends AbstractAction {

    public synchronized void run() {
        System.out.println("run thread prompt");

        /* Récupération des paramètres */
        ServerModel server = (ServerModel) this.getParam("server");
        Template layout = Template.getInstance();

        PromptPartView prompt = (PromptPartView) layout.getViewPart("prompt");

        String message = "";
        while (server.isConnected()) {
            try {
                while ((message = server.getReception()) != null) {
                    /* Affichage du message */
                    prompt.appendText(message);
                    this.wait(20);
                }
                this.wait(100);

                /* En cas de problèmes */
            } catch (IOException ex) {
                TemplateDialog.showInternalErrorDialog(ex.getMessage());
            } catch (InterruptedException ex) {
                TemplateDialog.showInternalErrorDialog(ex.getMessage());
            }
        }
    }

    public boolean init() {
        return true;
    }
}
